package com.yxq.mdt.app.modules.publish.ui.model;

import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.publish.ui.bean.MainPublishBean;
import com.yxq.mdt.app.modules.publish.ui.bean.PublishListBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

/**
 * 发布
 */
public class MainPublishModel implements IBaseModel {
    //发布视频/语音/图片
    public void setDoPublish(RequestBody body, ApiModel.CommonCallback<PublishListBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainPublishApi.class)
                .setDoPublish(body)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<PublishListBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onCodeError(PublishListBean baseEntity) throws Exception {
                        callback.onError(baseEntity.getMessage());
                    }

                    @Override
                    public void onSuccess(PublishListBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    @Override
    public void onDestroy() {

    }

}
